<?php
/**
 * 用户登录
 *
 * @author <judasnow@gmail.com>
 */
class auth extends CI_Controller{
	public function __construct(){
		parent::__construct();
		$this->load->library( 'user_auth' );
	}

	//异步的判断当前用户是否已经
	//登录系统
	public function is_login(){
		if( $this->user_auth->is_login() ){
			 //已经登录系统
			 //得到用户的信息
			 $user = $this->session->userdata( 'user' );
			 $user_obj = unserialize( $user['user_obj'] );
			 echo json_encode( array(
				 'res'=>TRUE
				 ) );
		}else{
			echo json_encode( array( 
				'res' => FALSE 
				) );
		}
	}

	public function login(){
		 $this->load->view( 'login' );
	}

	public function deny(){
		 $this->load->view( 'deny' );
	}

	public function do_login(){
		 if( !$this->user_auth->is_login() ){
			 //用户还没有登陆系统
			 //执行登陆操作
			 $this->user_auth->do_login();
		 }
		 header( 'Location: /' );
		 exit;
	}

	public function do_logout(){
		$this->user_auth->do_logout();
		header( 'Location: /' );
		exit;
	} 
}
